package com.dc.aimc.user.controller;

import com.dc.aimc.common.service.response.JsonResponse;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("demo")
public class DemoController {

    @PreAuthorize("hasAnyRole('admin')")
    @GetMapping("hello")
    public JsonResponse<Object> hello() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        System.out.println(authentication);
        return JsonResponse.success(authentication);
    }

    @PreAuthorize("hasAuthority('user:select')")
    @GetMapping("exception")
    public JsonResponse<String> exception() {
        throw new RuntimeException("test global exception");
    }
}
